<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<base href="<%=basePath%>" />
<meta charset="UTF-8">
<title>后台管理</title>
<link rel="stylesheet" type="text/css" href="css/common.css" />
<link rel="stylesheet" type="text/css" href="css/main.css" />
<script type="text/javascript" src="js/modernizr.min.js"></script>
<script type="text/javascript" src="js/jquery-1.8.3.js"></script>
<!-- 文本框验证 -->
<script type="text/javascript">
	$(function() {
		$("#tname").blur(checkUser);
		$("#password").blur(checkPwd);
		$("#email").blur(checkemail);
		$("#tel").blur(checktel);

		$("#myform").submit(function() {
			var flag = true;
			if (!checkUser())
				flag = false;
			if (!checkPwd())
				flag = false;
			if (!checkemail())
				flag = false;
			if (!checktel())
				flag = false;
			return flag;
		});
	});
	function checkUser() {
		var $name = $("#tname").val();
		var $uname = $("#uname");
		if ($name == "") {
			$uname.html("<img src='images/onError.gif'>用户名不能为空");
			return false;
		}
		var reg = /^[a-zA-Z0-9]{6,12}$/;
		if (reg.test($name) == false) {
			$uname.html("<img src='images/onError.gif'>用户名是由数字,字母组成，长度为6到12位");
			return false;
		} else {
			$uname.html("<img src='images/onCorrect.gif'>用户名输入正确");
			return true;
		}
	}
	function checkename(name) {
		$.post("teachers/checkName", {
			"tname" : name.value
		}, function(data) {
			if (data != 0) {
				data = '该用户已注册';
			} else {
				$uname.html("<img src='images/onCorrect.gif'>用户名输入正确");
			}
			//显示结果到页面
			var div1 = document.getElementById("uname");
			div1.innerHTML = data;
		});
	}

	function checkPwd() {
		var $password = $("#password").val();
		var $upassword = $("#upassword");
		if ($password == "") {
			$upassword.html("<img src='images/onError.gif'>密码不能为空");
			return false;
		}
		var reg = /^\d{6,12}$/;
		if (reg.test($password) == false) {
			$upassword.html("<img src='images/onError.gif'>密码长度6位");
			return false;
		} else {
			$upassword.html("<img src='images/onCorrect.gif'>密码输入正确");
			return true;
		}
	}
	function checkemail() {
		var $email = $("#email").val();
		var $uemail = $("#uemail");
		var reg = /^\w+@\w+(\.[a-zA-Z]{2,3})(\.[a-zA-Z]{1,2})?$/;
		if ($email == "") {
			$uemail.html("<img src='images/onError.gif'>电子邮件不能为空");
			return false;
		}
		if (reg.test($email) == false) {
			$uemail.html("<img src='images/onError.gif'>电子邮件格式不对");
			return false;
		} else {
			$uemail.html("<img src='images/onCorrect.gif'>电子邮件输入正确");
			return true;
		}
	}
	function checktel() {
		var $tel = $("#tel").val();
		var $utel = $("#utel");
		var reg = /^[1][358][0-9]{9}$/;
		if ($tel == "") {
			$utel.html("<img src='images/onError.gif'>手机不能为空");
			return false;
		}
		if (reg.test($tel) == false) {
			$utel.html("<img src='images/onError.gif'>手机不正确,已1358开头");
			return false;
		} else {
			$utel.html("<img src='images/onCorrect.gif'>手机输入正确");
			return true;
		}
	}
	
</script>
<script>
</script>
</head>
<body>
	<div class="topbar-wrap white">
		<div class="topbar-inner clearfix"></div>
	</div>
	<div class="container clearfix">
		<div class="sidebar-wrap">
			<div class="sidebar-title">
				<h1>菜单</h1>
			</div>
			<%@ include file="center.jsp"%>
		</div>
		<!--/sidebar-->
		<div class="main-wrap">

			<div class="crumb-wrap">
				<div class="crumb-list">
					<i class="icon-font"></i><a href="/jscss/admin/design/">首页</a><span
						class="crumb-step">&gt;</span><a class="crumb-name"
						href="#">新增教师信息</span></a><span class="crumb-step"></span>
				</div>
			</div>
			<!-- enctype="multipart/form-data" -->
			<div class="result-wrap">
				<div class="result-content">
					<form action="teachers/add" method="post" id="myform" name="myform">
						<table class="insert-tab" width="100%">
							<tbody>
								<tr>
									<th><i class="require-red">*</i>用 户 名：</th>
									<td><input class="common-text required" id="tname"
										name="tname" size="20" value="" type="text"
										onblur="checkename(this)" /> <spen id="uname"></spen></td>
								</tr>
								<tr>
									<th><i class="require-red">*</i>教师id：</th>
									<td><input class="common-text required" id="teid"
										name="teid" size="20" value="" type="text" /> <spen
											id="teid"></spen></td>
								</tr>


								<tr>
									<th><i class="require-red">*</i>角色：</th>
									<td><input class="common-text required" id="roleid"
										name="roleid" size="20" value="" type="text" /> <spen
											id="roleid"></spen></td>
								</tr>
								<tr>
									<th><i class="require-red">*</i>密码：</th>
									<td><input class="common-text required" id="password"
										name="password" size="20" value="" type="password" /> <spen
											id="upassword"></spen></td>
								</tr>
								<tr>
									<th><i class="require-red">*</i>subject：</th>
									<td><input class="common-text required" id="subjectid"
										name="subjectid" size="20" value="" type="text" /> <spen
											id="subjectid"></spen></td>
								</tr>
								<tr>
									<th><i class="require-red">*</i>class：</th>
									<td><input class="common-text required" id="classid"
										name="classid" size="20" value="" type="text" /> <spen
											id="classid"></spen></td>
								</tr>

								<tr>
									<th><i class="require-red">*</i>邮 箱：</th>
									<td><input class="common-text required" id="email"
										name="email" size="20" value="" type="text" /> <spen
											id="uemail"></spen></td>
								</tr>


								<tr>
									<th><i class="require-red">*</i>手机号码：</th>
									<td><input class="common-text required" id="tel"
										name="tel" size="20" value="" type="text" /> <spen id="utel"></spen></td>
								</tr>

 <tr>

								<tr>
									<th></th>
									<td><input value="提交" type="submit" name="submit"></td>
								</tr>
							</tbody>
						</table>
					</form>
				</div>
			</div>

		</div>
		<!--/main-->
	</div>
</body>
</html>
